<!DOCTYPE html>
<!--
Copyright 2011 Software Freedom Conservancy. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
  <title>response_test</title>
  <script src="test_bootstrap.js"></script>
  <script>
    goog.require('bot.Error');
    goog.require('bot.ErrorCode');
    goog.require('bot.response');
    goog.require('goog.testing.jsunit');
  </script>
</head>
<body>
<script>
function testCheckResponse_statusOk() {
  var obj = {status: 0, value: 'foo'};
  assertEquals(obj, bot.response.checkResponse(obj));
}

function testCheckResponse_valueHasMesage() {
  var threw = false;
  try {
    bot.response.checkResponse({
      status: 7,
      value: {
        message: 'Ouch'
      }
    });
  } catch (ex) {
    threw = true;
    assertEquals(7, ex.code);
    assertEquals('Ouch', ex.message);
  }
  assertTrue('Did not throw!', threw);
}

function testCheckResponse_valueIsString() {
  var threw = false;
  try {
    bot.response.checkResponse({
      status: 7,
      value: 'No soup for you'
    });
  } catch (ex) {
    threw = true;
    assertEquals(7, ex.code);
    assertEquals('No soup for you', ex.message);
  }
  assertTrue('Did not throw!', threw);
}

function testCheckResponse_noStatus() {
  var threw = false;
  try {
    bot.response.checkResponse({
      value: 'No soup for you'
    });
  } catch (ex) {
    threw = true;
    assertEquals(bot.ErrorCode.UNKNOWN_ERROR, ex.code);
    assertEquals('No soup for you', ex.message);
  }
  assertTrue('Did not throw!', threw);
}
</script>
</body>
</html>
